#include "KinectInteraction.h"
#include "pthread.h"
#include <opencv/highgui.h>
#include <opencv/cv.h>
#include <iostream>
#include <fstream>


KinectInteraction *kinect;
std::string *message;


/** @brief Initializes Kinect interaction
*   @param
*   @return
*
* Initializes Kinect interaction, calling the init()
* method of the interaction object.
*
*/
void init(){
    kinect = new KinectInteraction(),
    kinect->init();

}



/** @brief Function for kinect thread
*   @param
*   @return
*
*
*
*/
void *graphics(){

    bool die(false);
    int iter = 0;
    //ofstream output;
    //output.open ("output.xml");


    Mat pro;

   //kinect->train();

    while (!die) {

        kinect->run(iter);
        //kinect->draw();


        //if(iter % 10 ==0) kinect->detect();

        //Recordning commented, TODO: move to function



        /*if(iter == 150){
            kinect->record(pro);
            FileStorage fs("handpos.yml", FileStorage::WRITE);
            if (!fs.isOpened()){
                fs.open("handpos.yml", FileStorage::WRITE);
            }

            std::cout << "done!" << std::endl;
            fs << "handpos" << pro;
            fs.release();

        }*/




        //usleep(50);

    	char k = cvWaitKey(5);
		if( k == 27 ){
//			output.close();
			break;
		}
        iter++;
    }


    return 0;
}

int main(int argc, char **argv){
    init();

    message = new std::string("bleh");
    graphics();


    return 0;
}
